package com.xdemo.personal.httpserver;

import com.xdemo.core.MessageType;
import com.xdemo.msg.HttpBean;
import com.xdemo.msg.IMessage;
import com.xdemo.msg.IMessageRecognizer;
import com.xdemo.personal.httpserver.msg.FileUploadMessage;
import com.xdemo.personal.httpserver.msg.FileUploadUnknownErrorMsg;

public class HttpMessageRecognizer implements IMessageRecognizer<String,HttpBean> {

	@Override
	public IMessage<String> createMessage(HttpBean httpBean) {
		if(httpBean.getUri().equals(MessageType.FileUpload)) {
			return new FileUploadMessage(httpBean);
		}else if(httpBean.getUri().equals(MessageType.FileUploadUnknownError)) {
			return new FileUploadUnknownErrorMsg(httpBean);
		}else if(httpBean.getUri().length() == 9) {
			String _url = httpBean.getUri();
			httpBean.setUri(MessageType.FileRequestShortUrl);
			HttpRequestShortUrlMsg _msg = new HttpRequestShortUrlMsg(httpBean);
			_msg.setShortUrl(_url);
			return _msg;
		}
		return null;
	}
	
}
